home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / internet / amitcp3.0b / src.lha / src / util / online / online.c next >
Encoding:
C/C++ Source or Header  |  1996-09-08  |  5.0 KB  |  217 lines

  1. RCS_ID_C="$Id: online.c,v 3.1 1994/02/22 03:30:02 ppessi Exp $";
  2. /*
  3.  * online.c --- Send an online/offline command to a SANA-II device
  4.  *
  5.  * Author: ppessi <Pekka.Pessi@hut.fi>
  6.  *
  7.  * Copyright © 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>,
  8.  *            Helsinki University of Technology, Finland.
  9.  *            All rights reserved. 
  10.  *
  11.  * Created      : Sat Feb 20 14:15:07 1993 ppessi
  12.  * Last modified: Tue Feb 22 02:39:05 1994 ppessi
  13.  */
  14.  
  15. #include "online_rev.h"
  16. static const char version[] = VERSTAG " "
  17.   "Copyright © 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>\n"
  18.                    "Helsinki University of Technology, Finland.\n"
  19.                    "All rights reserved.\n";
  20.  
  21. /****** netutil.doc/offline *************************************************
  22. *
  23. *  NAME
  24. *       Offline - put a SANA-II device offline 
  25. *
  26. *  TEMPLATE
  27. *       Offline DEV=DEVICE devicename[/unit] [UNIT unit]
  28. *
  29. *  DESCRIPTION 
  30. *       Offline sends the S2_OFFLINE command to the given SANA-II device
  31. *       driver and unit. This command is normally used to disconnect SANA-II
  32. *       device driver from the network adapter hardware. Device driver does
  33. *       not accept any more read or write requests.
  34. *
  35. *  EXAMPLES 
  36. *       This command puts the SLIP offline, which frees then the serial port
  37. *       to your use.
  38. *
  39. *       OFFLINE slip.device/1
  40. *
  41. *  NOTES
  42. *       The offline figures out its identity from its CLI program name.
  43. *
  44. *  SEE ALSO
  45. *       Online, sana2.device/S2_OFFLINE
  46. *
  47. *****************************************************************************
  48. *
  49. */
  50.  
  51. /****** netutil.doc/online **************************************************
  52. *
  53. *  NAME
  54. *       Online - put a SANA-II device online 
  55. *
  56. *  TEMPLATE
  57. *       Online DEV=DEVICE devicename[/unit] [UNIT unit]
  58. *
  59. *  DESCRIPTION 
  60. *       Online sends the S2_ONLINE command to the given SANA-II device driver
  61. *       and unit. The device driver restarts the network adapter hardware and
  62. *       accepts read and write request again.
  63. *
  64. *  EXAMPLES 
  65. *
  66. *       This command puts the Commodore Ethernet driver online.
  67. *
  68. *       Online a2065.device/0
  69. *
  70. *  NOTES
  71. *       The online figures out its identity from its CLI program name.
  72. *
  73. *  SEE ALSO
  74. *       Offline, sana2.device/S2_ONLINE
  75. *
  76. *****************************************************************************
  77. *
  78. */
  79.  
  80. #include <exec/types.h>
  81. #include <exec/devices.h>
  82. #include <exec/ports.h>
  83. #include <exec/semaphores.h>
  84. #include <exec/memory.h>
  85. #include <exec/execbase.h>
  86.  
  87. #include <dos/dos.h>
  88. #include <dos/dosextens.h>
  89.  
  90. #ifdef __SASC 
  91. #include <clib/exec_protos.h>
  92. extern struct ExecBase* SysBase;
  93. #include <pragmas/exec_sysbase_pragmas.h>
  94. #include <proto/dos.h>
  95. #else
  96. #include <clib/exec_protos.h>
  97. #include <clib/dos_protos.h>
  98. #endif
  99.  
  100. #include <devices/sana2.h>
  101. #include <net/sana2errno.h>
  102. #include <string.h>
  103.  
  104. extern int main(char *myname);
  105.  
  106. __asm LONG _main(void)
  107. {
  108.   struct Process *p;
  109.   LONG retval = 128;
  110.  
  111.   SysBase = *(struct ExecBase**)4;
  112.   DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37L);
  113.   if (DOSBase) {
  114.     p = (struct Process *)SysBase->ThisTask;
  115.     if (p->pr_CLI) {
  116.       struct CommandLineInterface *cli = (void *)(p->pr_CLI << 2);
  117.       retval = main((char *)(cli->cli_CommandName<<2)+1);
  118.     } else {
  119.       /* No CLI. A process or a son of WB? */
  120.     }
  121.     CloseLibrary((struct Library *)DOSBase);
  122.   }
  123.  
  124.   return retval;
  125. }
  126.  
  127. struct DosLibrary *DOSBase;
  128. struct ExecBase *SysBase;
  129.  
  130. int
  131. main(char *myname)
  132. {
  133.   struct MsgPort *port = NULL;
  134.   struct IOSana2Req *req = NULL;
  135.   struct RDArgs *rdargs = NULL;
  136.   LONG args[10] = { 0 };
  137.   char *name; LONG unit;
  138.   LONG retval = 0;
  139.   LONG openerr = 1;
  140.  
  141.   rdargs = ReadArgs("DEV=DEVICE/A,UNIT/N", args, NULL);
  142.   if (!rdargs) {
  143.     retval = 10;
  144.     PrintFault(IoErr(), myname);
  145.     goto close;
  146.   }
  147.  
  148.   if (port = CreateMsgPort()) 
  149.     req = CreateIORequest(port, sizeof(*req));
  150.   if (!port || !req) {
  151.     retval = 40;
  152.     PrintFault(ERROR_NO_FREE_STORE, "CreateIORequest");
  153.     goto close;
  154.   }
  155.  
  156.   name = (STRPTR) args[0];
  157.   /* find unit number */
  158.   {
  159.     int namlen = strlen(name);
  160.     char c;
  161.  
  162.     if (args[1]) {
  163.       unit = *(LONG *)args[1];
  164.     } else {
  165.       unit = 0;
  166.       c = '0';
  167.       do {
  168.     unit = unit * 10 + c - '0';
  169.     c = name[--namlen];
  170.       }
  171.       while (c >= '0' && c <= '9');
  172.  
  173.       if (c != '/') {
  174.     retval = 10;
  175.     PrintFault(ERROR_REQUIRED_ARG_MISSING, myname);
  176.     goto close;
  177.       }
  178.       name[namlen] = '\0';    
  179.     }
  180.     if (openerr = OpenDevice(name, unit, (struct IORequest *)req, 0L)) {
  181.       retval = 10;
  182.       Sana2PrintFault("OpenDevice", req);
  183.       goto close;
  184.     }
  185.   }
  186.  
  187.   switch (FindArg("online,offline", FilePart(myname))) {
  188.   case 0: 
  189.     req->ios2_Req.io_Command = S2_ONLINE;
  190.     name = "S2_ONLINE";
  191.     break;
  192.   case 1:
  193.     req->ios2_Req.io_Command = S2_OFFLINE;
  194.     name = "S2_OFFLINE";
  195.     break;
  196.   default:
  197.     Printf("But what to do?\n");
  198.     goto close;
  199.   }
  200.   DoIO((struct IORequest *)req);
  201.   if (req->ios2_Req.io_Error) {
  202.     Sana2PrintFault(name, req);
  203.   }
  204.  
  205.  close:
  206.   if (!openerr) 
  207.     CloseDevice((struct IORequest*)req);
  208.   if (req)
  209.     DeleteIORequest((struct IORequest *)req);
  210.   if (port)
  211.     DeleteMsgPort(port);
  212.   if (rdargs)
  213.     FreeArgs(rdargs);
  214.  
  215.   return (retval);
  216. }
  217.